using System;
using System.Linq;
using GiveGraphModel;

namespace GiveGraphMappers
{
    public class ServiceMapper : AbstractGiveGraphMapper<Service>
    {
        #region Overrides of AbstractGiveGraphMapper<Service>

        protected override int GetElementKey(Service t)
        {
            return t.ResourceId;
        }

        #endregion

        public Service GetByUser(int memberId)
        {
            return Call<Service>((ctx) => (DoGetByUser(ctx, memberId)));
        }

        protected Service DoGetByUser(GiveGraphContext ctx, int memberId)
        {
            return (from service in ctx.Services
                    where service.ProviderMember.MemberId == memberId
                    select service).SingleOrDefault();
        }
    }
}